package joSaysHello.client.gui;

import joSaysHello.shared.entity.Hello;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ServerReplyDlg extends DialogBox {
	
	final Label textToServerLabel = new Label();
	final HTML serverResponseLabel = new HTML();
	
	public ServerReplyDlg()
	{
		super("Jo");
		VerticalPanel msg = new VerticalPanel();
		msg.add(new HTML("<b>Sending hello to the server:</b>"));
		textToServerLabel.setText("Hello");
		msg.add(textToServerLabel);
		msg.add(new HTML("<br><b>Server replies:</b>"));
		msg.add(serverResponseLabel);
		this.getDisplay().add(msg);
	}
	
	public void showServerError(Throwable caught)
	{
		serverResponseLabel.setText("Error: "+caught.getMessage());
		dlg.setText("Jo - Failure");
		serverResponseLabel.addStyleName("serverResponseLabelError");
		super.show();
	}
	public void showServerReply(Hello hello)
	{
		serverResponseLabel.setText(hello != null ? "Hello "+hello.getWho().getNickname()+"!" : "You're not logged in! o.O");
		dlg.setText("Jo");
		serverResponseLabel.removeStyleName("serverResponseLabelError");
		super.show();
	}

}
